package com.bionic.banking.logic.controller;

import com.bionic.banking.dao.AbstractDao;
import com.bionic.banking.logic.exception.InvalidParameterException;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public abstract class AbstractBean<T> {

    private AbstractDao<T> dbObject;

    protected abstract AbstractDao<T> getDaoObject(); //{   return dbManager.GetDaoObject(); }

    public AbstractBean() throws InstantiationException, IllegalAccessException {
        dbObject = getDaoObject();
    }

    public T getDetails(Integer id) {
        try {
            return (T) dbObject.findById(id);
        } catch (SQLException ex) {
            Logger.getLogger(AbstractBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public Boolean create(T entity) throws InvalidParameterException, SQLException {
        return dbObject.create(entity) > -1;
    }

    public boolean update(T entity) throws SQLException {
        return dbObject.update(entity);
    }

    public void remove(Integer id) throws SQLException {
        dbObject.remove(id);
    }

    public List<T> getAll() throws SQLException {
        return dbObject.findAll();
    }

    public void setMaxRows(int maxRows) {
        dbObject.setMaxRows(maxRows);
    }

    public int getMaxRows() {
        return dbObject.getMaxRows();
    }
}